package cn.yunhe.controller;

import cn.yunhe.entity.Product;
import cn.yunhe.service.ProductService;
import cn.yunhe.util.Paganation;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
import java.io.IOException;

@WebServlet("/GetAllProductsByGtypeid")
public class GetAllProductsByGtypeid extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int gtypeid = Integer.parseInt(req.getParameter("gtypeid"));
        int pageNo = Integer.parseInt(req.getParameter("pageNo"));
        ProductService productService = new ProductService();
        Paganation<Product> paganation = productService.getAllProductsByGid(pageNo, gtypeid);
        req.setAttribute("paganation", paganation);
        req.setAttribute("gtypeid",gtypeid);
        req.getRequestDispatcher("product-gtypeid.jsp").forward(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }
}
